<template>
  <div class="customerOverview-container">
    <div class="customerOverview-page">
      <el-card>
        <div>
           <el-button size="small" type="primary" @click="showAddgj('','addCustomer')">新增跟进</el-button>
        </div>
        <el-table :data="list" v-loading="listLoading" border style="width: 100%; margin: 20px 0">
          <el-table-column
            label="跟进时间"
            align="center"
            min-width="100">
            <template slot-scope="scope">
               {{scope.row.trackingTime}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="跟进产品线"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.goodsLineName}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="开发阶段"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.developStep}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="跟进人"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.trackingUserName}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="跟进方式"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.trackingTypeName}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="跟进内容"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.trackingContent}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="跟进类型"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.isInvalid == 0 ? '有效' : '无效'}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="创建人"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.createUserName}}
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            min-width="150">
            <template slot-scope="scope">
              <el-button type="text" @click="showAddgj(scope.row,'edit')" v-if="scope.row.isCanUpdate == 1">编辑</el-button>
              <el-button type="text" @click="delItem(scope.row)" v-if="scope.row.isCanUpdate == 1">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :page-size="listQuery.pageSize"
            :page-sizes="[10,15,20]"
            :current-page.sync="listQuery.pageNum"
            :total="count">
          </el-pagination>
        </div>
      </el-card>
    </div>
    <addGj ref="addGj" @getList="getList"></addGj>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {formatDate} from '@/utils/date';
import store from '@/store'
import {getCustomerOption, addRelatio, delRelation,} from '@/api/partner'
import {developTrackingList,customerNewBaseInfo,customerNewDelTracking} from '@/api/company'
import addGj from './addGj';
const defaultListQuery={
  customerId:'',
  isMy:1,
  "pageNum" : 1,
  "pageSize" : 10
};
export default {
  name: "customerSycl",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      list:[],
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      count: 0,
      listLoading: false,
      info:{}
    }
  },
  components : {
    addGj
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },
  created() {

  },
  filters: {

  },
  methods:{
    delItem(item){
      this.$confirm('确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        customerNewDelTracking({trackingId:item.trackingId}).then(()=>{
          this.getList()
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
    init(customerId){
      this.listQuery.customerId = customerId;
      this.getList();
      this.getInfo()
    },
    //获取客户基本信息
    getInfo(){
      customerNewBaseInfo({customerId:this.listQuery.customerId}).then((res)=>{
        this.info = res
      })
    },
    //显示新增跟进
    showAddgj(item,type){
      let data = {}
      if(type == 'edit'){
        data = JSON.parse(JSON.stringify(item))
      }
      data.customerId = this.listQuery.customerId
      data.customerName = this.info.customerName
      this.$refs.addGj.showTracking(data,type)
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getList();
    },
    //获取列表
    getList() {
      this.listLoading = true;
      developTrackingList(this.listQuery).then(response => {
        this.list = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },
  }
}
</script>

<style lang="scss">


</style>
